/*
ID:luongho3
LANG:C++
TASK:holstein
*/
#include <iostream>
#include <fstream>
#define N_TYPE 25
#define N_VITA 30
using namespace std;
ifstream fin("holstein.in");
ofstream fout("holstein.out");
int n_vita, n_type, n_bit;
int req[N_VITA];
int feed[N_TYPE][N_VITA];
int temp[N_TYPE];
int bit[N_TYPE];
void read() {
     int i,j;   
     fin >> n_vita;
     for (i=1;i<=n_vita;++i) {
         fin >> req[i];
     }
     fin >> n_type;
     for (i=1;i<=n_type;++i) {
         for (j=1;j<=n_vita;++j) {
             fin >> feed[i][j];
         }
     }
}
void toBin(int n) {
     int i;
     n_bit = 0;
     for (i=1;i<=n_type;++i) {
         bit[i] = n%2;
         if (bit[i] == 1) {
            ++n_bit;
         }
         n /= 2;
     }     
}
void next(int n_scoop) {
     int i,j,k;
     int pivot = n_type;
     for (i=1;i<=n_scoop;++i) {
         for (j=pivot;j>=1;--j) {
             if (bit[j] == 1) {
                pivot = j-1;
                //if it is possible to move this 1-bit ahead
                //then move it
                //else turn to the next 1-bit
                if (j<n_type && bit[j+1]==0) {
                   bit[j] = 0;
                   bit[j+1] = 1;
                   //pull the more significant bits toward the new moved bit
                   int index=j+2;
                   for (k=j+2;k<=n_type;++k) {
                       if (bit[k]==1) {                          
                          bit[k]=0;
                          bit[index]=1;
                          ++index;
                       }
                   }
                   return;
                }
             }
         }
     }
     //reached the last combination
     //back to start
     for (i=1;i<=n_type;++i) {
         if (i<=n_scoop) {
            bit[i] = 1;
         }
         else {
              bit[i] = 0;
         }
     }
}
bool back_to_start(int n_scoop) {
     int i;
     for (i=1;i<=n_type;++i) {
         if (i<=n_scoop) {
            if (bit[i]!=1) {
               return false;
            }
         }
         else {
              if (bit[i]!=0) {
                 return false;
              }
         }
     }     
     return true;
}
bool solve(int n_scoop) {
     //get first combination
     int i,j;
     bool flag;
     for (i=1;i<=n_type;++i) {
         if (i<=n_scoop) {
            bit[i] = 1;
         }
         else {
              bit[i] = 0;
         }
     }
     do {
        flag=true;
        for (i=1;i<=n_vita;++i) {
            temp[i] = 0;
            for (j=1;j<=n_type;++j) {
                temp[i] += (feed[j][i] * bit[j]);
            }
            if (temp[i] < req[i]) {
               flag = false;
               break;
            }
        }
        if (flag) {
           return true;
        }
        //move to next combination   
        next(n_scoop);
     } while (!back_to_start(n_scoop)); // no next combination exists
     return false;
}
int main() {
    read();
    int i,j;
    for (i=1;i<=n_type;++i) {
        if (solve(i)) {
           fout << i;
           for (j=1;j<=n_type;++j) {
               if (bit[j] == 1) {
                  fout <<" "<<j;
               }
           }
           fout<<"\n";
           break;
        }
    }
    return 0;
}
